package com.bwie.controller;

import com.bwie.config.NacosConfig;
import com.bwie.pojo.User;
import com.bwie.service.UserService;
import com.bwie.utils.R;
import com.bwie.vo.AdminLoginVo;
import com.bwie.vo.PageInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: TaoShiHao
 * @Date: 2025/4/21 16:09
 * @Description:
 **/
@RestController
@RequestMapping("/user/index")
@Api(tags = "用户管理")
//获取 配置文件
@RefreshScope
public class IndexController {

    @Autowired
    UserService userService;


    @Value("${server.port}")
    private Integer serverPort;

    @Autowired
    NacosConfig nacosConfig;

   @Value("${site.ip}")
    private String ip;
    /**
     * 根据用户ID获取用户
     *
     * @param id
     * @return
     */
    @PostMapping("/getUserById/{id}")
    @ApiOperation(value = "根据用户ID获取用户信息")
    public R getUserById(@PathVariable(name = "id") Integer id) {
        System.out.println("serverPort:"+serverPort);
        return userService.getUserById(id);
    }
    @PostMapping("/getConfig")
    public R getConfig(){
        return R.OK(nacosConfig.getClassName());
    }
    @PostMapping("/getNacosIp")
    public R getNacosIp(){
        return R.OK(ip);
    }

    /**
     * 管理员 登录
     * @param adminLoginVo
     * @return
     */
    @PostMapping("/adminLogin")
    public R adminLogin(@RequestBody AdminLoginVo adminLoginVo){

        return userService.adminLogin(adminLoginVo);
    }
    @PostMapping("/getUserList")
    public R getUserList(@RequestBody PageInfoVo pageInfoVo){
        return userService.getUserList(pageInfoVo);

    }
    @PostMapping("/userReg")
    @ApiOperation(value = "用户注册")
    public R userReg(@RequestBody @Validated User user){
        return userService.userReg(user);
    }

    @PostMapping("/checkUser")
    @ApiOperation(value = "商户审核")
    public R checkUser(@RequestBody User user){
      return userService.checkUser(user);
    }
    @PostMapping("/getMyInfo")
    @ApiOperation(value = "获取用户自己的信息")
    public R getMyInfo(){
        return userService.getMyInfo();
    }
    @PostMapping("/updateUser")
    @ApiOperation(value = "修改个人用户信息")
    public R updateUser(@RequestBody @Validated User user){
        return userService.updateUser(user);
    }
}
